/*
 * PrioUtil.java 13.06.2013
 *
 * Copyright (c) 2013 1&1 Internet AG. All rights reserved.
 *
 * $Id$
 */
package de.tum.wi.som.util;

import java.util.ArrayList;
import java.util.List;

import de.tum.wi.som.Node;

/**
 * Util methods for prioritizing nodes.
 * @author epollok
 *
 */
public class PrioUtil {

    /**
     * Takes a list of scheduledNodes and the sink of a project to determine all nodes whose predecessor is already
     * scheduled in the project graph. Returns a list of all accessible nodes given the scheduled nodes and the project
     * sink.
     *
     * @param scheduledNodes A list of all nodes already scheduled in the project graph
     * @param source The soiurce of the project
     * @param remainingNodes All nodes that have not been scheduled yet.
     * @return Returns a list of all accessible nodes given the scheduled nodes and the project sink.
     */
    public static List<Node> determineAccesibleNodes(List<Node> scheduledNodes, Node source, List<Node> remainingNodes) {
        List<Node> accessibleNodes = new ArrayList<Node>();
        accessibility: for (Node node : remainingNodes) {
            for (Node predecessor : node.getPredecessors()) {
                if (predecessor != source && !scheduledNodes.contains(predecessor)) {
                    continue accessibility;
                }
            }
            accessibleNodes.add(node);
        }
        return accessibleNodes;
    }
}
